var App = angular.module('weiXinModule', ['weiXinController', 'weiXinService', 'weiXinFilter', 'weiXinDirective']);

var weiXinController = angular.module('weiXinController', ['ui.router']);

var weiXinService = angular.module("weiXinService", ['weiXinModule']);

var weiXinFilter = angular.module("weiXinFilter", ['weiXinModule']);

var weiXinDirective = angular.module("weiXinDirective", ['weiXinModule']);

App.run(function ($rootScope, $http) {
    $rootScope.$on('$locationChangeStart', function (event, msg) {
        // console.log('开始改变$location')
    });
    $rootScope.$on('$locationChangeSuccess', function (event, msg) {
        // console.log('结束改变$location')
        EdeyeAdmin.openScroll(0);
        $('.modal-backdrop').remove();
    });
});

App.config(['$qProvider', '$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', '$compileProvider', function ($qProvider, $stateProvider, $urlRouterProvider, $httpProvider, $locationProvider, $compileProvider) {

    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|sms|javascript):/);

    $locationProvider.hashPrefix('');

    var systemDefaultProvider = [

        ['/portal', '/weixin/portal/portal.html', 'portalCtl'],

        //库管员
        ['/kgy/store/create', '/weixin/kgy/store/create.html', 'kgyStoreCreateCtl'],
        ['/kgy/store/edit', '/weixin/kgy/store/edit.html', 'kgyStoreEditCtl'],
        ['/kgy/store/page', '/weixin/kgy/store/page.html', 'kgyStorePageCtl'],
        ['/kgy/order/create', '/weixin/kgy/order/create.html', 'kgyOrderCreateCtl'],
        ['/kgy/order/edit', '/weixin/kgy/order/edit.html', 'kgyOrderEditCtl'],
        ['/kgy/order/page', '/weixin/kgy/order/page.html', 'kgyOrderPageCtl'],
        ['/kgy/order/recall/page', '/weixin/kgy/order/recall/page.html', 'kgyOrderRecallPageCtl'],
        ['/kgy/lock/page', '/weixin/kgy/lock/page.html', 'kgyLockPageCtl'],

        //申领人
        ['/slr/notice/page', '/weixin/slr/notice/page.html', 'slrNoticePageCtl'],
        ['/slr/order/create', '/weixin/slr/order/create.html', 'slrOrderCreateCtl'],
        ['/slr/order/page', '/weixin/slr/order/page.html', 'slrOrderPageCtl'],
        ['/slr/order/edit', '/weixin/slr/order/edit.html', 'slrOrderEditCtl'],

        //紧急审批人
        ['/jjspr/notice/page', '/weixin/jjspr/notice/page.html', 'jjsprNoticePageCtl'],
        ['/jjspr/order/page', '/weixin/jjspr/order/page.html', 'jjsprOrderPageCtl'],

        //审批人
        ['/spr/notice/page', '/weixin/spr/notice/page.html', 'sprNoticePageCtl'],
        ['/spr/order/page', '/weixin/spr/order/page.html', 'sprOrderPageCtl'],

        //通知管理
        ['/operation/msg', '/weixin/operation/msg.html', 'operationMsgCtl'],
    ];

    $urlRouterProvider.otherwise("/portal");

    angular.forEach(systemDefaultProvider, function (obj) {
        $stateProvider.state(obj[0], {
            // params: {'param':null},
            url: obj[0] + '?param',
            // templateUrl: obj[1],
            templateUrl: obj[1],
            controller: obj[2]
        });
    });
}]);
